<%@ page import="java.sql.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>显示所有专业信息</title>
</head>
<body>
<a href="addMajor.jsp">添加专业</a>
<%
    //1.加载驱动程序
    Class.forName("com.mysql.cj.jdbc.Driver");
    //2.建立与数据库的连接
    String url = "jdbc:mysql://localhost:3306/javaeelab";
    Connection conn = DriverManager.getConnection(url, "root", "root");
    //3.创建命令对象
    Statement st=conn.createStatement();
    //4.执行SQL语句
    String sql = "SELECT * FROM tb_major";
    ResultSet rs=st.executeQuery(sql);
    //5.获取并输出查询结果
    out.println("<table border='1'>");
    out.println("<tr><td>专业ID</td><td>专业名称</td>><td>编辑</td></tr>");
    while (rs.next()){
        out.println("<tr>");
        out.println("<td>"+rs.getString("id")+"</td>");
        out.println("<td>"+rs.getString("major_name")+"</td>");
        out.println("<td>");
        out.println("<a href='updateMajor.jsp?id="+rs.getString("id")+"&name="+rs.getString("major_name")+"'>修改</a>");
        out.println("<a href='deleteMajor.jsp?id="+rs.getString("id")+"'>删除</a>");
        out.println("</td>");
        out.println("</tr>");
    }
    out.println("</table>");
    //6.释放资源
    rs.close();	st.close();	conn.close();
%>
</body>
</html>
